package com.atguigu.wordcount.multiplejob;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ClassName Ex1Reducer
 * @DeScription Ex1Reducer
 * @Author 剧情再美终是戏
 * @Date 2019/11/20 14:54
 * @Version 1.0
 **/

// 输入： atguigu:a.txt 1
// 输出： atguigu:a.txt 3 atguigu:b.txt 3
public class Ex1Reducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    private IntWritable out_value = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable value : values) {
            sum += value.get();
        }
        out_value.set(sum);
        context.write(key, out_value);
    }
}
